#! /usr/bin/env python
# -*- coding: utf-8 -*-

import jenkins
import os
template_xml="deploy_demo.xml"
jenkins_root = '/data/jenkins/'
appname = 'demo4'
ip = '192.168.5.54'
port = '9898'
ips= ip.strip('192.168.')
job_deploy_name = 'test_'+appname+'_'+ips+'_deploy'
print(job_deploy_name)
#dir_name = jenkins_root+'jobs/'+job_build_name
#if not os.path.exists(dir_name):
#    os.makedirs(dir_name)

with open(template_xml) as f:
    profile = f.read()

xml=profile.replace("IP", ip).replace("PORT", port).replace("appname",appname)

#与网页版Jenkins登录的账号、密码一致
server = jenkins.Jenkins('http://192.168.18.196:8080/', username='admin', password='Wgmf@1234!')
xml = xml.strip()
server.create_job(job_deploy_name,xml)

